
#include "../includes.h"


unsigned char EBTXParameter[30];

EBT_ EBTxMessage[NUM_OF_EBTX_MESSAGE] = {
	{"Fa",7},		// eSELFTEST
	{"Ea",8},		// ePSDM
	{"At",8},		// ePHM
	{"Aw",8},		// eTIMEMODE
	{"Ab",10},		// eGMTOFFSET
	{"Ac",11},		// eDATE
	{"Aa",10},		// eTIME
	{"As",20},		// ePHP
	{"Az",11},		// eANTDLY
	{"Bj",8},		// eLEAP
	{"Cf",7},		// eDEFAULT
	{"En",22},		// eTRAIM
	{"Cj",7},		// eRECEIVERID
	{"Bo",8},		// eUTC_OFFSET
	{"Ag",8},		// eMASK_ANGLE
	{"Bb",8},		// eSAT_STATUS
	{"Aq",8},		// eAT_CORRECTION
	{"Ap",25},		// eSET_USER_DATUM
	{"Ao",8},		// eSELECT_DATUM
	{"S3",8},		// SYNC15 �� d1.
	{"S4",10},		// SYNC15 �� d2.
	{"S5",10},		// SYNC15 �� d3.
	{"Ay",11}		// SYNC15 1PPS offset
};



EBR_ EBRxMessage[NUM_OF_EBRX_MESSAGE] = {
    {"Aa",10,	EBRX_TOD},
    {"Ab",10,	EBRX_GMT_OFFSET},
    {"Ac",11,	EBRX_DATE},
    {"Ad",11,	EBRX_LATITUDE},
    {"Ae",11,	EBRX_LONGITUDE},
    {"Af",15,	EBRX_HEIGHT},
    {"As",20,	EBRX_PHP},
    {"At",8,	EBRX_PHM},
    {"Aw",8,	EBRX_TIME_MODE},
    {"Az",11,	EBRX_CABLEDELAY},
    {"Cb",9,	EBRX_ALMANAC_IN},
    {"Be",33,	EBRX_ALMANAC_OUT},
    {"Bj",8,	EBRX_LEAPSEC},
    {"Cf",7,	EBRX_SETTODEFAULT},
    {"Cj",294,	EBRX_RECEIVERID},
    {"Ea",76,	EBRX_PSDM},
    {"En",69,	EBRX_TRAIM},
    {"Fa",9,	EBRX_SELFTEST},
    {"Sz",8,	EBRX_POWERFAILURE},
    {"Bo",8,	EBRX_UTC_OFFSET},
    {"Ag",8,	EBRX_MASK_ANGLE},
    {"Bb",92,	EBRX_SAT_STATUS},
    {"Aq",8,	EBRX_AT_CORRECTION},
    {"Ap",25,	EBRX_SET_USER_DATUM},
    {"Ao",25,	EBRX_SELECT_DATUM},
    {"Ay",11,	EBRX_1PPS_OFFSET}     	};

char rcv_debug_display;

/* Initialization */
void Init_EBRxMessage();
void Init_EBTxMessage();

/* EB Tx Handling */
void RequestEB(int);

void EB_Event_Handling(void);



/* EB Rx Handling */
int EBGetCommandID(BYTE *,WORD);
void EBHandleIt(int,int,BYTE *);

/* EB Rx Procedures */
void PSDMpro(int, BYTE *);
void RECEIVERIDpro(int,BYTE*);
void SELFTESTpro(int,BYTE*);
void PHMpro(int,BYTE*);
void PHPpro(int,BYTE*);
void LEAPSECpro(int,BYTE*);
void TIMEMODEpro(int,BYTE*);
void GMTOFFSETpro(int,BYTE*);
void CABLEDELAYpro(int,BYTE*);
void SETTODEFAULTpro(int,BYTE*);

void UTC_OFFSETpro(int, BYTE *);
void SATSTATUSpro(int, BYTE *);
void MASKANGLEpro(int, BYTE *);

/* EB Tx Procedures */
void SetGMTOFFSET(char,char);
void SetDATE(WORD,BYTE,BYTE);
void SetTIME(BYTE,BYTE,BYTE);
void SetPOSITIONHOLD();
void SetANTDLY(long);
void Set1PPSoffset(long);

void SetPSDM(char);
void SetPHM(char);
void SetTIMEMODE(char);
void SetLEAPSECOND(char);
void SetUTCOFFSET(char);
void SetSATSTATUS(char);
void SetMASKANGLE(unsigned char);
void SetTRAIM(char);
void traim_1pps(char);


char	Setting_GMTOFFSET();
char	Setting_ANTDLY();
char	Setting_POSITION();
char	Setting_EBID();
char	Setting_TIMEMODE();


char 	Enable_MASK();
char 	Enable_SATSTATUS();
char 	Enable_PSDM();
char 	Enable_PHM();
char 	Disable_PHM();
char 	Enable_PHP();

char 	SetEBToDefault();

int Enable_TRAIM();


void TRAIMpro(int,unsigned char*);

char start_traim_query = TRAIM_QUERY_NULL;
unsigned int traim_value1 = 0;
unsigned int traim_value2 = 0;
unsigned int traim_value3 = 0;

unsigned char psdm_watch_val[2][100];
unsigned char psdm_watch_stop = 0;

void Init_EBCMD(void)
{
//	Init_EBRxMessage();
//	Init_EBTxMessage();
	rcv_debug_display = OFF;
}


void EB_Event_Handling(void)
{
/*
	if( SYSTEM.EB.PHP_Enable == ON ){
    	if( Enable_PHP() == OK ){
        	SYSTEM.EB.PHP_Enable = OFF;
        }
    }
	if( SYSTEM.EB.PHM_Disable == ON ){
		if( Disable_PHM() == OK ){
			SYSTEM.EB.PHM_Disable = OFF;
		}
	}
*/

	if( SYSTEM.EB.PHP_Enable == ON ){
    	if( Enable_PHP() == OK ){SYSTEM.EB.PHP_Enable = OFF;	}
    }
	if( SYSTEM.EB.PHM_Disable == ON ){
		if( Disable_PHM() == OK ){	SYSTEM.EB.PHM_Disable = OFF;	}
	}
	if( SYSTEM.EB.EB_Default == ON ){
		if( SetEBToDefault() == OK ){	SYSTEM.EB.EB_Default = OFF;	}
	}

}


/* ---------------------------------------------------------------------
File Name     : EBIO.C
Last Updated  : Thu  98-02-12 17:02:09
Function Name : RequestEB
Description   : E/B
Parameters    : E/B Tx
--------------------------------------------------------------------- */
void RequestEB(int comm)
{
    int i,l;
    unsigned char checksum;
	unsigned char buffer[100];

    // length
    l = EBTxMessage[comm].Length-3;

	// Header & Name
	buffer[0] = '@';
	buffer[1] = '@';
	buffer[2] = EBTxMessage[comm].Name[0];
	buffer[3] = EBTxMessage[comm].Name[1];

	// Parameter
    for(i = 0; i < l-4; i++ ){
    	buffer[i+4] = EBTXParameter[i];
    }
    // checksum ;
    for (i = 2, checksum = 0; i < l; i++){
        checksum ^= buffer[i];
    }

	// checksum & Tail
    buffer[l] = checksum;
    buffer[l+1] = 0x0D;
    buffer[l+2] = 0x0A;

    SendMessageToEB(buffer,EBTxMessage[comm].Length);
}


/*----------------------------------------------------------------------
 File Name : EBcmd.C
 Last Updated : 98-02-12 5:45
 Function Name : EBGetCommandID
 Description : SCC18 E/B

 Parameters : SCC1-Rx
 Return Values : NO!
----------------------------------------------------------------------*/
int EBGetCommandID(BYTE *Buffer,WORD length)
{
    int i, j, command, checksumlength;
    BYTE checksum;

	int next_count;

	next_count = 0;
	//kang printf("EBGetCommandID\n");
    for( i = 0; i < length; i++){
        if( Buffer[i] == '@' && Buffer[i+1] == '@'){
            command = -1; checksum = 0;
			if(monitor.eb){
				//U0puts("<@@>");
				TransmitMessage((BYTE*)"<@@>",PORT_CONTROL);
				
				//printf("<@@>:%d\n",i); //kang
			}
            // 명령어가 들어온 것인지 확인.
          
            for(j = 0; j < NUM_OF_EBRX_MESSAGE; j++){                     //NUM_OF_EBRX_MESSAGE = 26
                if( Buffer[i+2] == EBRxMessage[j].Name[0] && Buffer[i+3] == EBRxMessage[j].Name[1]
					// Rx Count 가 해석된 메시지의 길이보다 길거나 같을 때만 인정.
					&& (EBRxMessage[j].Length+i) <= length)
				{
					command = EBRxMessage[j].Command;
   	                checksumlength = EBRxMessage[j].Length - 3;
   	                if(monitor.eb)
					{
						//U0puts("<Name>");
                        
						sprintf(MESG,"<Name:%c%c, Len:%d/%d/%d>",
							EBRxMessage[j].Name[0], EBRxMessage[j].Name[1],
							i, EBRxMessage[j].Length, length);
                        
						
						/*kang
                        printf("==<Name:%c%c, Len:%d/%d/%d>\n", 
							EBRxMessage[j].Name[0], EBRxMessage[j].Name[1],
							i, EBRxMessage[j].Length, length-i);
						*/
							
						TransmitMessage((BYTE*)MESG,PORT_CONTROL);
					}
       	            break;
                }
            }


            if ( command == -1 ){
				//printf("not found:%d\n",i);
				continue;
			}
			
            // 여기에서 @@Cj ( Receiver ID ) 명령어는
            // 첵섬을 끝까지 검사하지 않고, 바로 넘긴다.
            // 매뉴얼과 다른 점: 맨 끝 줄 약 28Byte가 공백으로 넘어온다.
            for( j = i+2; j < checksumlength + i ; j++) {	checksum ^= Buffer[j]; }


            if( (command == EBRX_RECEIVERID) || (Buffer[checksumlength + i] == checksum)){
				if(monitor.eb){
					//U0puts("<CHKSUM>\r\n");
					TransmitMessage((BYTE*)"<CHKSUM>",PORT_CONTROL);
				}
/*
		       	if(SYSTEM.IO.CTRL_PORT.MODE == UDEBUG){
        			sprintf((char*)MESG,"(%d)",command);
	            	TransmitMessage(MESG,DEBUG_PORT);
    		    }
*/
				buf_sync15.Rx_Match_TimeOut = 0;

                EBHandleIt(command,i,Buffer);
                i += checksumlength;

                next_count = i+3;

            }
            else {
                continue;
            }

/*
            if( (command != EBRX_RECEIVERID) && (Buffer[checksumlength + i] != checksum)){
                continue;
            }
            else {
                EBHandleIt(command,i,Buffer);
                i += checksumlength;
            }
*/
        }
    }
//return;
	return next_count ;
	/*
	if( next_count != 0){
		for( i = 0; i < (length-next_count); i++ ){
			Buffer[i] = Buffer[next_count+i];
		}
	}
	return (length-next_count);
	*/
}


/*----------------------------------------------------------------------
 File Name :
 Last Updated : 98-02-17 7:51
 Function Name :
 Description : 
 Parameters :
 Return Values :
----------------------------------------------------------------------*/
void EBHandleIt(int comm, int count, BYTE *buff)
{

    if (SYSTEM.IO.CTRL_PORT.MODE == UDEBUG9){
	/*
       	sprintf((char*)MESG,
       	                    "[%3d,%3d,%3d,%3d,%3d]"
       	                    //"[0x%02X,0x%02X,0x%02X,0x%02X] [0x%02X,0x%02X,0x%02X,0x%02X]"
       	                    //"[0x%02X,0x%02X,0x%02X,0x%02X] [0x%02X,0x%02X,0x%02X,0x%02X]"
       	                    //"[0x%02X,0x%02X,0x%02X,0x%02X] [0x%02X,0x%02X,0x%02X,0x%02X]"
       	                    //"[0x%02X,0x%02X,0x%02X,0x%02X] [0x%02X,0x%02X,0x%02X,0x%02X]"
       	                    "[%02X,%02X,%02X,%02X] [%02X,%02X,%02X,%02X]"
       	                    "[%02X,%02X,%02X,%02X] [%02X,%02X,%02X,%02X]"
       	                    "[%02X,%02X,%02X,%02X] [%02X,%02X,%02X,%02X]"
       	                    "[%02X,%02X,%02X,%02X] [%02X,%02X,%02X,%02X]"
       	                  //  "[%c,%c,%c,%c] [%c,%c,%c,%c] [%c,%c,%c,%c] [%c,%c,%c,%c]"
       						"\r\n"
       						,SYSTEM.TIME.GPS.SECOND,comm,count,SYSTEM.TIME.TOD_MatchCounter,TimeSliceCounter
       						,buff[0],buff[1],buff[2],buff[3],buff[4],buff[5],buff[6],buff[7]
       						,buff[8],buff[9],buff[10],buff[11],buff[12],buff[13],buff[14],buff[15]
       						,buff[16],buff[17],buff[18],buff[19],buff[20],buff[21],buff[22],buff[23]
       						,buff[24],buff[25],buff[26],buff[27],buff[28],buff[29],buff[30],buff[31]
       					//	,buff[0],buff[1],buff[2],buff[3],buff[4],buff[5],buff[6],buff[7]
       						);
        TransmitMessage((BYTE*)MESG,DEBUG_PORT);
	*/	
    }   
    
    switch(comm){

        case EBRX_TOD:
                    break;
        case EBRX_GMT_OFFSET:
                    GMTOFFSETpro(count, buff);
                    break;
        case EBRX_DATE:
                    break;
        case EBRX_LATITUDE:
                    break;
        case EBRX_LONGITUDE:
                    break;
        case EBRX_HEIGHT:
                    break;
        case EBRX_PHP:
                    PHPpro(count, buff);
                    break;
        case EBRX_PHM:
                    PHMpro(count, buff);
                    break;
        case EBRX_TIME_MODE:
                    TIMEMODEpro(count, buff);
                    break;
        case EBRX_CABLEDELAY:
                    CABLEDELAYpro(count, buff);
                    break;
        case EBRX_ALMANAC_IN:
                    break;
        case EBRX_ALMANAC_OUT:
                    break;
         case EBRX_LEAPSEC:
                    LEAPSECpro(count, buff);
                    break;
        case EBRX_SETTODEFAULT:
        			SETTODEFAULTpro(count,buff);
                    break;
        case EBRX_RECEIVERID:
                    RECEIVERIDpro(count, buff);
                    break;
        case EBRX_PSDM:	
                    PSDMpro(count, buff);
                    break;
        case EBRX_TRAIM:
                    TRAIMpro(count, buff);
                    break;
        case EBRX_SELFTEST:
                    SELFTESTpro(count, buff);
                    break;
        case EBRX_POWERFAILURE:
                    break;

        case EBRX_UTC_OFFSET:
        			UTC_OFFSETpro(count,buff);
                    break;
        case EBRX_MASK_ANGLE:
        			MASKANGLEpro(count,buff);
                    break;
		case EBRX_SAT_STATUS:
					SATSTATUSpro(count,buff);
					break;
		case EBRX_AT_CORRECTION:
					break;
		case EBRX_SET_USER_DATUM:
					break;
		case EBRX_SELECT_DATUM:
					break;
    }
}

/*----------------------------------------------------------------------
 Last Updated : 98-02-17 7:52
 Function Name : RECEIVERIDpro
 Description : Motorola
----------------------------------------------------------------------*/
void RECEIVERIDpro(int index, BYTE *command )
{
	char c;
	int i;

	register EB_	*EB = &SYSTEM.EB;

	if(	command[index+123] == 0x0D &&
		command[index+124] == 0x0A &&
		command[index+125] == 'S' &&
		command[index+126] == 'O' &&
		command[index+127] == 'F' &&
		command[index+128] == 'T' &&
		command[index+129] == 'W' &&
		command[index+130] == 'A' &&
		command[index+131] == 'R' &&
		command[index+132] == 'E' &&
		command[index+133] == ' ' &&
		command[index+134] == 'D' &&
		command[index+135] == 'A' &&
		command[index+136] == 'T' &&
		command[index+137] == 'E'  ) {


		// Model Number copy
		for( i = 0; i < 15; i++ ){
			EB->MODEL[i] = command[index+164+i];
		}
		EB->MODEL[i] = 0;
		// Serial number copy
		for( i = 0; i < 15; i++ ){
			EB->SERIAL[i] = command[index+220+i];
		}
		EB->SERIAL[i] = 0;

		// Software Ver
		for( i = 0; i < 11; i++ ){
			if(command[index+84+i] == ' '){break;}
			EB->SWVER[i] = command[index+84+i];
		}
		EB->SWVER[i] = 0;

		// Software Rev
		for( i = 0; i < 11; i++ ){
			if(command[index+112+i] == ' '){break;}
			EB->SWREV[i] = command[index+112+i];
		}
		EB->SWREV[i] = (char)0;
		
		// Software Date
		for( i = 0; i < 11; i++ ){
			if(command[index+140+i] == ' '){
				if(i>8){break;}
			}
			EB->SWDATE[i] = command[index+140+i];
		}
		EB->SWDATE[i] = (char)0;
		
		// HWDR
		c = command[index+192];
		if(c=='1'){EB->SUBID = SYNC15_ORI;}
		else if(c=='2'){EB->SUBID = SYNC15_N;}
		else if(c=='3'){EB->SUBID = SYNC15_T;}
			
		if(command[index] == '@' && command[index+1] == '@' && command[index+2] == 'C' && command[index+3] == 'j') {
			//if(EB->MODEL[0] == 'G' && EB->MODEL[1] == 'S' ){
			//EB->SERIAL
			if(EB->SERIAL[0] == 'G' && EB->SERIAL[1] == 'T' ){
				EB->ID = SYNC_15;	
    		    MessageOut("Sync15 Detected\r\n");
			}
			else if( EB->MODEL[0] == 'R' && EB->MODEL[1] == '5' ){
				EB->ID = UT_PLUS_ONCORE;
    		    MessageOut("UT+ Detected\r\n");
			}
    		else{
    		    MessageOut("Unknown Detected\r\n");
    	    }
			
		}

		//TransmitnMessage(EB->MODEL,15,PORT_CONTROL);

	}
	
}


// UT-PLUS only
void UTC_OFFSETpro(int index, BYTE *command)
{
	SYSTEM.EB.LEAPSECOND = (char)command[index+4];
}

void SETTODEFAULTpro(int index, BYTE *command)
{
	SYSTEM.EB.settodefault = YES;
}

void TRAIMpro(int index, unsigned char *command)
{

	int i;

	SYSTEM.EB.TRAIM.FLAG 			= (char)command[index+5];

	SYSTEM.EB.TRAIM.LIMIT			= (unsigned short)command[index+6] *256 + (unsigned short)command[index+7];
	SYSTEM.EB.TRAIM.CTRLMODE 		= (char)command[index+8];

	SYSTEM.EB.TRAIM.PULSE 			= (char)command[index+19];
	SYSTEM.EB.TRAIM.PULSESYNC 		= (char)command[index+20];
	SYSTEM.EB.TRAIM.SOL_STATUS 		= (char)command[index+21];
	SYSTEM.EB.TRAIM.STATUS 			= (char)command[index+22];
	SYSTEM.EB.TRAIM.ACCURACY 		= (unsigned short)command[index+23] *256 + (unsigned short)command[index+24];
	SYSTEM.EB.TRAIM.SAWTOOTH 		= (signed char)command[index+25];


	for( i = 0; i < 8; i++){
		SYSTEM.EB.TRAIM.SAT[i] 		= (char)command[index+26+i*5];
		SYSTEM.EB.TRAIM.SATTIME[i] 	= 	(unsigned int)command[index+27+i*5] * 256 * 256 * 256 +
										(unsigned int)command[index+28+i*5] * 256 * 256 +
										(unsigned int)command[index+29+i*5] * 256 +
										(unsigned int)command[index+30+i*5];
	}

	traim_value1 = (((unsigned char)command[index+4] << 24)&0xFF000000) |
					(((unsigned char)command[index+5] << 16)&0x00FF0000) |
					(((unsigned char)command[index+6] << 8)&0x0000FF00) |
					((unsigned char)command[index+7]&0x000000FF);
		
	traim_value2 = (((unsigned char)command[index+8] << 24)&0xFF000000) |
					(((unsigned char)command[index+19] << 16)&0x00FF0000) |
					(((unsigned char)command[index+20] << 8)&0x0000FF00) |
					((unsigned char)command[index+21]&0x000000FF);
		
	traim_value3 = (((unsigned char)command[index+22] << 24)&0xFF000000) |
					(((unsigned char)command[index+23] << 16)&0x00FF0000) |
					(((unsigned char)command[index+24] << 8)&0x0000FF00) |
					((unsigned char)command[index+25]&0x000000FF);
	
	if(start_traim_query == TRAIM_QUERY_ING)
	{
		start_traim_query = TRAIM_QUERY_DONE;
		
		LogIt3(LOG_CATA1_NORM, LOG_CATA2_NOTHING, LOG_1PPS_VAL, traim_value1, traim_value2, traim_value3);
		//sprintf(MESG,"TRAIM: %08X, %08X, %08X\r\n", traim_value1, traim_value2, traim_value3);
		//TransmitMessage((BYTE*)MESG,DEBUG_PORT);
	}

}


/*----------------------------------------------------------------------*/
// Last Updated : 98-03-09 4:05
// Function Name :
// Description : SELF TEST+ Antenna
// Parameters :
// Return Values :
/*----------------------------------------------------------------------*/
void SELFTESTpro(int index, BYTE *command)
{


//    if(!command[index + 4] && !command[index + 5]){
    if(!(command[index + 4]&0x3F) && !command[index + 5]){
        SYSTEM.EB.SELFTEST = OK;
    }
    else {
        SYSTEM.EB.SELFTEST = FAIL;
    }

    switch( command[index+4]&0xC0 ){
    	case 0x80:	SYSTEM.EB.ANTENNA = ANTENNA_OPENED;		break;
    	case 0x40:	SYSTEM.EB.ANTENNA = ANTENNA_SHORTED;	break;
    	case 0x00:	SYSTEM.EB.ANTENNA = OK;					break;
    }

}


void CABLEDELAYpro(int index, BYTE *command)
{

    SYSTEM.EB.ANTDLY    = (long)command[index+4]*16777216 + (long)command[index+5]*65536
                        + (long)command[index+6]*256 + (long)command[index+7];
}

int year_err_cnt=0;
/*----------------------------------------------------------------------*/
// File Name : EBCmd.C
// Last Updated : 2000-04-21 17:02
// Function Name : PSDMpro
// Description : Position-Status-Data message Decoding
//               GPSL Month + day = accumulated Day
// Parameters :
// Return Values :
/*----------------------------------------------------------------------*/
void PSDMpro(int index, BYTE *command)
{
	int i;

	unsigned short year;
	unsigned char mon,day,hr,min,sec;

	char message[20];

	//if(SYSTEM.EB.STATUS == EB_STATUS_RUN){
	/************************************************************************************/
	// [2001-09-26 11:38�]
	// PSDM
	/************************************************************************************/
	   	year = (WORD)(command[index+6]*256 + command[index+7]);
	   	mon = (BYTE)command[index+4];
   		day = (BYTE)command[index+5];
   		hr = (BYTE)command[index+8];
   		min = (BYTE)command[index+9];
   		sec = (BYTE)command[index+10];

		memcpy(psdm_watch_val[0], &command[index], 76);
		
		if( (year < 1998 || year > 2024) ||
			(mon < 1 || mon > 12) || (day < 1 || day > 31) || (hr > 23) || (min > 59) || (sec > 60)){
		    //sprintf((char*)MESG,"\r\nYear Error: %d-%d-%d %d:%d:%d",
		    //	year, (BYTE)command[index+4], (BYTE)command[index+5], 
		    //	(BYTE)command[index+8], (BYTE)command[index+9], (BYTE)command[index+10]);
        	//TransmitMessage((BYTE*)MESG,DEBUG_PORT);
        	if(SYSTEM.EB.STATUS == EB_STATUS_RUN && psdm_watch_stop == 0){
        		year_err_cnt++;
        		//TLogIt(TLOG_YEAR_ERR,year_err_cnt);
        		
        		memcpy(psdm_watch_val[1], &command[index], 76);
        		psdm_watch_stop = 1;
        	}
			return;
		}
	
	if(!psdm_watch_stop){
		memcpy(psdm_watch_val[0], &command[index], 76);
	}
	
    
    SYSTEM.EB.PSDM = OK;
    SYSTEM.EB.RxCheckCounter = 0;

    SYSTEM.EB.rxflag = OK;
    SYSTEM.EB.RxCounter++;


    SYSTEM.POSITION.CURRENT.LAT    = (long)command[index+15]*16777216 + (long)command[index+16]*65536
                                        + (long)command[index+17]*256 + (long)command[index+18];
    SYSTEM.POSITION.CURRENT.LON    = (long)command[index+19]*16777216 + (long)command[index+20]*65536
                                        + (long)command[index+21]*256 + (long)command[index+22];
    SYSTEM.POSITION.CURRENT.HEI    = (long)command[index+23]*16777216 + (long)command[index+24]*65536
                                        + (long)command[index+25]*256 + (long)command[index+26];

    SYSTEM.TRACK.DOP = (short int)(command[index+35]*256 + command[index+36]);
    SYSTEM.TRACK.DOPTYPE = (BYTE)command[index+37];

    SYSTEM.TRACK.VISIBLE = command[index+38];
    SYSTEM.TRACK.TRACKED = command[index+39];


	if(start_unlock){
		SYSTEM.TRACK.VISIBLE = 0;
    	SYSTEM.TRACK.TRACKED = 0;
	}
	
	
    for( i = 0; i < 8; i++){
        SYSTEM.TRACK.SAT[i].ID = command[index+40+i*4];
        SYSTEM.TRACK.SAT[i].MODE = command[index+41+i*4];
        SYSTEM.TRACK.SAT[i].SS = command[index+42+i*4];
        SYSTEM.TRACK.SAT[i].STATUS = command[index+43+i*4];
        
        if(start_unlock){
        	SYSTEM.TRACK.SAT[i].ID = command[index+40+i*4];
	        SYSTEM.TRACK.SAT[i].MODE = 0;
	        SYSTEM.TRACK.SAT[i].SS = 0;
	        SYSTEM.TRACK.SAT[i].STATUS = 0;
    	}
    }
	
    SYSTEM.TRACK.STATUS = (BYTE)command[index+72];
	
   	SYSTEM.EB.TIME.YEAR = (WORD)(command[index+6]*256 + command[index+7]);
   	SYSTEM.EB.TIME.MONTH = (BYTE)command[index+4];
   	SYSTEM.EB.TIME.DAY = (BYTE)command[index+5];
   	SYSTEM.EB.TIME.HOUR = (BYTE)command[index+8];
   	SYSTEM.EB.TIME.MINUTE = (BYTE)command[index+9];
   	SYSTEM.EB.TIME.SECOND = (BYTE)command[index+10];
   	
   	if(eb_tdebug){SYSTEM.EB.TIME.YEAR = SYSTEM.EB.TIME.YEAR -1;}
   		
   	if(TEMP_TOD == OFF){
   		TEMP_TOD = ON;
   		SYSTEM.TIME.GPS = SYSTEM.EB.TIME;
   		LogStartFlag = ON;
   	}
	

    /* calculate position in survey mode */
	if(SYSTEM.POSITION.PositionMode == POSITION_MODE_AVERAGING &&
		SYSTEM.EB.SELFTEST == OK){
    	Survey_Position();
    }


//	CheckLock();

   	//if(SYSTEM.IO.CTRL_PORT.MODE == UDEBUG || monitor.eb){
   	//if(monitor.eb){
	//	sprintf((char*)MESG,"\n[!,%3d,%3d]",TimeSliceCounter,SYSTEM.TIME.TOD_MatchCounter);
	//	TransmitMessage((BYTE*)MESG,DEBUG_PORT);
    //}
    
/*
    if(monitor.eb == ON){

//		if( !(SYSTEM.TRACK.DOPTYPE & 0x80)){


			TransmitMessage((BYTE*)"***EB***",DEBUG_PORT);

			for( i = 0; i < 76; i++ ){


				message[0] = hex_char[(command[index+i]>>4)&0xf];
				message[1] = hex_char[(command[index+i]    )&0xf];
				message[2] = ' ';

				TransmitnMessage((BYTE*)message,3,DEBUG_PORT);



//				sprintf(MESG,"%.2x ",command[index+i]);
//				TransmitMessage(MESG,DEBUG_PORT);
			}
			TransmitMessage((BYTE*)"\r\n",DEBUG_PORT);
//		}
	}
*/
}




/*----------------------------------------------------------------------*/
// Last Updated : 98-03-10 9:59�
// Function Name :
// Description : PHP position; position
// Parameters :
// Return Values :
/*----------------------------------------------------------------------*/
void PHPpro(int index, BYTE *command)
{
    int result;

    result = OK;

    if(command[index+4] != (BYTE)((SYSTEM.EB.PHP.POSITION.LAT >> 24) & 0x000000ff))    result = FAIL;
    if(command[index+5] != (BYTE)((SYSTEM.EB.PHP.POSITION.LAT >> 16) & 0x000000ff))    result = FAIL;
    if(command[index+6] != (BYTE)((SYSTEM.EB.PHP.POSITION.LAT >> 8) & 0x000000ff))     result = FAIL;
    if(command[index+7] != (BYTE)(SYSTEM.EB.PHP.POSITION.LAT & 0x000000ff))            result = FAIL;

    if(command[index+8] != (BYTE)((SYSTEM.EB.PHP.POSITION.LON >> 24) & 0x000000ff))    result = FAIL;
    if(command[index+9] != (BYTE)((SYSTEM.EB.PHP.POSITION.LON >> 16) & 0x000000ff))    result = FAIL;
    if(command[index+10] != (BYTE)((SYSTEM.EB.PHP.POSITION.LON >> 8) & 0x000000ff))    result = FAIL;
    if(command[index+11] != (BYTE)(SYSTEM.EB.PHP.POSITION.LON & 0x000000ff))           result = FAIL;

    if(command[index+12] != (BYTE)((SYSTEM.EB.PHP.POSITION.HEI >> 24) & 0x000000ff))   result = FAIL;
    if(command[index+13] != (BYTE)((SYSTEM.EB.PHP.POSITION.HEI >> 16) & 0x000000ff))   result = FAIL;
    if(command[index+14] != (BYTE)((SYSTEM.EB.PHP.POSITION.HEI >> 8) & 0x000000ff))    result = FAIL;
    if(command[index+15] != (BYTE)(SYSTEM.EB.PHP.POSITION.HEI & 0x000000ff))           result = FAIL;

    if(command[index+16] != 0)  result = FAIL;

    if( result == OK ){     SYSTEM.EB.PHP.match = OK;    }
    else {        			SYSTEM.EB.PHP.match = FAIL;  }
}


void PHMpro(int index, BYTE *command)
{

     if(command[index+4] == 1)
        SYSTEM.EB.PHM = ENABLE;
    else if(command[index+4] == 0)
        SYSTEM.EB.PHM = DISABLE;
}


void TIMEMODEpro(int index, BYTE *command)
{

    if( command[index+4] == 0 ){
        SYSTEM.EB.TIMEMODE = TIMEMODE_GPS;
    }
    else{
        SYSTEM.EB.TIMEMODE = TIMEMODE_UTC;
    }
}


/* ---------------------------------------------------------------------
Last Updated  : Wed  10-01-97 13:55:23
Function Name : LEAPSECpro
Description   : get leap second pending status, ( every 3500 seconds )
                set TOD message at the end of the month
Parameters    :
--------------------------------------------------------------------- */
void LEAPSECpro(int index, BYTE *command)
{

    if( command[index+4] == 0 ){
        SYSTEM.EB.LEAPSECPENDING = NO;
    }

    else {
        if ( command[index+4] == 1){
            SYSTEM.EB.LEAPSECPENDING = PLUS;
        }
        else if ( command[index+4] == 2){
            SYSTEM.EB.LEAPSECPENDING = MINUS;
        }
    }
}


void GMTOFFSETpro(int index, BYTE *command)
{

    SYSTEM.EB.LOCALHOUR = (char)command[index+5];
    SYSTEM.EB.LOCALMINUTE = (char)command[index+6];

    if ( command[index+4] != 0 ) {
        SYSTEM.EB.LOCALHOUR *= -1;
        SYSTEM.EB.LOCALMINUTE *= -1;
    }
}

void SATSTATUSpro(int index, unsigned char *command)
{
	int i;

    SYSTEM.EB.SATSTATUS = OK;

    //SYSTEM.TRACK.VISIBLE = command[index+4];
    for( i = 0; i < 12; i++){
        SYSTEM.TRACK.VIS_SAT[i].ID = command[index+5+i*7];
        SYSTEM.TRACK.VIS_SAT[i].EL = command[index+8+i*7];
        SYSTEM.TRACK.VIS_SAT[i].AZ = command[index+9+i*7]*256 +command[index+10+i*7];
        SYSTEM.TRACK.VIS_SAT[i].HEALTH = command[index+11+i*7];
    }
}

void MASKANGLEpro(int index, unsigned char *command)
{
	SYSTEM.TRACK.MASK = command[index+4];
}


void SetPSDM(char mode)
{
	if(mode == ENABLE){
		EBTXParameter[0] = 0x01;		RequestEB(ePSDM);
	}
	else if( mode == DISABLE) {
		EBTXParameter[0] = 0x00;		RequestEB(ePSDM);
	}
}

void SetPHM(char mode)
{
	if(mode == ENABLE){
		EBTXParameter[0] = 0x01;		RequestEB(ePHM);
	}
	else if( mode == DISABLE) {
		EBTXParameter[0] = 0x00;		RequestEB(ePHM);
	}
	else if( mode == POLL){
		EBTXParameter[0] = 0xFF;		RequestEB(ePHM);
	}
}

void SetTIMEMODE(char mode)
{
	if(mode == TIMEMODE_UTC){
		EBTXParameter[0] = 0x01;		RequestEB(eTIMEMODE);
	}
	else if( mode == TIMEMODE_GPS) {
		EBTXParameter[0] = 0x00;		RequestEB(eTIMEMODE);
	}
}

void SetLEAPSECOND(char mode)
{
	if(mode == POLL){
		EBTXParameter[0] = 0x00;		RequestEB(eLEAP);
	}
}

void SetUTCOFFSET(char mode)
{
	if(mode == POLL){
		EBTXParameter[0] = 0x00;		RequestEB(eUTC_OFFSET);
	}
}

void SetSATSTATUS(char mode)
{
	if(mode == ON){
		EBTXParameter[0] = 0x01;		RequestEB(eSAT_STATUS);
	}
}

void SetMASKANGLE(unsigned char angle)
{
	char buf[20];
//	EBTXParameter[0] = angle;			RequestEB(eMASK_ANGLE);
	//Satellite Cutoff Angle//
	sprintf(buf,"ECUTOFF %d\r\n",angle);
	write(fdEB,buf,strlen(buf));
	printf("OEMV2 ECUTOFF %d\r\n",angle);
}


void SetTRAIM(char mode)
{
    int i;

	if( mode == ENABLE ){
	    EBTXParameter[0] = 1;
    	EBTXParameter[1] = 1;	// Enable
	}
	else if( mode == DISABLE ){
	    EBTXParameter[0] = 0;
    	EBTXParameter[1] = 0;	// Enable
	}

    EBTXParameter[2] = (unsigned char)((SYSTEM.EB.TRAIM.T_LIMIT>>8)&0x00FF);
   	EBTXParameter[3] = (unsigned char)(SYSTEM.EB.TRAIM.T_LIMIT&0x00FF);
    EBTXParameter[4] = 1;
   	for( i = 0; i < 10; i++){
       	EBTXParameter[5+i] = 0;
   	}
   	RequestEB(eTRAIM);
}

void traim_1pps(char mode)
{
    int i;

	EBTXParameter[0] = 1;
    EBTXParameter[1] = 1;	// Enable
	
    EBTXParameter[2] = (unsigned char)((SYSTEM.EB.TRAIM.T_LIMIT>>8)&0x00FF);
   	EBTXParameter[3] = (unsigned char)(SYSTEM.EB.TRAIM.T_LIMIT&0x00FF);
   	
   	if( mode == ENABLE ){
    	EBTXParameter[4] = 1; // 1pps
    }
    else if( mode == DISABLE ){
    	EBTXParameter[4] = 0; // 1pps
    }
    
   	for( i = 0; i < 10; i++){
       	EBTXParameter[5+i] = 0;
   	}
   	RequestEB(eTRAIM);
}

void SetDATE(WORD year, BYTE month, BYTE day)
{

    EBTXParameter[0] = month;
    EBTXParameter[1] = day;
    EBTXParameter[2] = (unsigned char)(year/256);
    EBTXParameter[3] = (unsigned char)(year%256);

    RequestEB(eDATE);
}

void SetTIME(BYTE hour, BYTE minute, BYTE second)
{

    EBTXParameter[0] = hour;
    EBTXParameter[1] = minute;
    EBTXParameter[2] = second;

    RequestEB(eTIME);
}

void SetGMTOFFSET(char hour, char minute)
{
    BYTE sign;

    sign = (hour > 0) ? 0:0xff;

    EBTXParameter[0] = sign;
    EBTXParameter[1] = (hour >0) ? hour : -hour;
    EBTXParameter[2] = minute;

    RequestEB(eGMTOFFSET);
}


void SetANTDLY(long delay)
{

    EBTXParameter[0] = (unsigned char)((delay>>24) & 0x000000FF);
    EBTXParameter[1] = (unsigned char)((delay>>16) & 0x000000FF);
    EBTXParameter[2] = (unsigned char)((delay>>8) & 0x000000FF);
    EBTXParameter[3] = (unsigned char)(delay & 0x000000FF);

    RequestEB(eANTDLY);
}


void Set1PPSoffset(long off)
{

    EBTXParameter[0] = (unsigned char)((off>>24) & 0x000000FF);
    EBTXParameter[1] = (unsigned char)((off>>16) & 0x000000FF);
    EBTXParameter[2] = (unsigned char)((off>>8) & 0x000000FF);
    EBTXParameter[3] = (unsigned char)(off & 0x000000FF);

    RequestEB(e1PPS_OFFSET);
}

void SetPOSITIONHOLD()
{

    EBTXParameter[0] = (BYTE)(SYSTEM.EB.PHP.POSITION.LAT >> 24) & 0x000000ff;
    EBTXParameter[1] = (BYTE)(SYSTEM.EB.PHP.POSITION.LAT >> 16) & 0x000000ff;
    EBTXParameter[2] = (BYTE)(SYSTEM.EB.PHP.POSITION.LAT >> 8) & 0x000000ff;
    EBTXParameter[3] = (BYTE)SYSTEM.EB.PHP.POSITION.LAT & 0x000000ff;

    EBTXParameter[4] = (BYTE)(SYSTEM.EB.PHP.POSITION.LON >> 24) & 0x000000ff;
    EBTXParameter[5] = (BYTE)(SYSTEM.EB.PHP.POSITION.LON >> 16) & 0x000000ff;
    EBTXParameter[6] =  (BYTE)(SYSTEM.EB.PHP.POSITION.LON >> 8) & 0x000000ff;
    EBTXParameter[7] =  (BYTE)SYSTEM.EB.PHP.POSITION.LON & 0x000000ff;

    EBTXParameter[8] =  (BYTE)(SYSTEM.EB.PHP.POSITION.HEI >> 24) & 0x000000ff;
    EBTXParameter[9] =  (BYTE)(SYSTEM.EB.PHP.POSITION.HEI >> 16) & 0x000000ff;
    EBTXParameter[10] = (BYTE)(SYSTEM.EB.PHP.POSITION.HEI >> 8) & 0x000000ff;
    EBTXParameter[11] = (BYTE)SYSTEM.EB.PHP.POSITION.HEI & 0x000000ff;

    EBTXParameter[12] = 0;  // GPS ellipsoid height reference

    SYSTEM.EB.PHP.match = FAIL;

    RequestEB(ePHP);
}




char Enable_PSDM()
{

    if ( SYSTEM.EB.PSDM == OK){
        MessageOut("PSDM - Enabled!\r\n");
        return YES;
    }
    else if(SYSTEM.EB.PSDM == FAIL || SYSTEM.EB.PSDM == UNDEFINED){


       	if(SYSTEM.IO.CTRL_PORT.MODE == UDEBUG){
        	//sprintf((char*)MESG,"(%d)",SYSTEM.EB.PSDM);
            TransmitMessage((BYTE*)"PSDM retry to enable...\r\n",DEBUG_PORT);
        }

        //MessageOut("PSDM retry to enable...\r\n");

        SetPSDM(ENABLE);
    }
    return NO;
}


char Enable_SATSTATUS()
{

    if ( SYSTEM.EB.SATSTATUS == OK){
        MessageOut("SAT. status - Enabled!\r\n");
        return YES;
    }
    else if(SYSTEM.EB.SATSTATUS == FAIL || SYSTEM.EB.SATSTATUS == UNDEFINED){
        MessageOut("SAT. status retry to enable...\r\n");
        SetSATSTATUS(ENABLE);
    }
    return NO;
}

char Enable_MASK()
{

	if( SYSTEM.TRACK.MASK == CONFIG.MASK ){
        sprintf((char*)MESG,"Mask Angle:%d\r\n",SYSTEM.TRACK.MASK);
		MessageOut(MESG);
		return YES;
	}
	else {
        MessageOut("Mask angle retry...\r\n");
        SetMASKANGLE(CONFIG.MASK);
    }
    return NO;
}


int Enable_TRAIM()
{
    if ( SYSTEM.EB.TRAIM.FLAG == ON && SYSTEM.EB.TRAIM.CTRLMODE == ON && SYSTEM.EB.TRAIM.PULSE == ON){
        MessageOut("TRAIM. status - Enabled!\r\n");
        return YES;
    }
    else {
        MessageOut("TRAIM retry to enable...\r\n");
        SetTRAIM(ENABLE);
    }
    return NO;
}

char Enable_PHM()
{

    if (SYSTEM.EB.PHM == ENABLE){
        MessageOut("PHM State => Enable!\r\n");
        SYSTEM.EB.UnlockedDelayCounter += 60;
        return YES;
    }
    else {
        MessageOut("PHM enable still ING\r\n");
        SetPHM(ENABLE);
    }
    return NO;
}



char Disable_PHM()
{

   if(SYSTEM.EB.PHM == DISABLE){
        MessageOut("PHM State => Disable!\r\n");
        SYSTEM.EB.UnlockedDelayCounter += 60;
        return YES;
    }
    else{

        MessageOut("PHM disable still ING\r\n");
        SetPHM(DISABLE);
    }
    return NO;
}



/*----------------------------------------------------------------------*/
// File Name : EBcmd.c
// Last Updated : 98-03-10 10:57�
// Function Name :
// Description : 
// Parameters :
// Return Values :
/*----------------------------------------------------------------------*/

char Enable_PHP()
{

    // consists of 3 steps
    // 1 - disable PHM
    // 2 - enable  PHP
    // 3 - enable  PHM

	if ( ++SYSTEM.EB.PHP.Counter > 10 ) {

       	SYSTEM.EB.PHP.TryCounter++;

   		SYSTEM.EB.PHP.STEP = disablePHM;
   		SYSTEM.EB.PHP.Counter = 0;

       	if ( SYSTEM.EB.PHP.TryCounter == 4 ) {

       		SYSTEM.EB.PHP.TryCounter = 0;
       		return OK;
       	}
	}

	if( SYSTEM.EB.PHP.STEP == disablePHM ) {

        SYSTEM.EB.UnlockedDelayCounter = 60;

        if( SYSTEM.EB.PHM == DISABLE){

        	// Averaging �: ����
        	SYSTEM.POSITION.Survey = SURVEY_OFF;

            SYSTEM.EB.PHP.STEP = enablePHP;
            SYSTEM.EB.PHP.match = NO;
        } else  {
        	SetPHM(DISABLE);
        }
	}

	if( SYSTEM.EB.PHP.STEP == enablePHP ) {

        if( SYSTEM.EB.PHP.match == YES ){
            SYSTEM.EB.PHP.STEP = enablePHM;
        } else {
            SetPOSITIONHOLD();
        }
	}

	if( SYSTEM.EB.PHP.STEP == enablePHM ) {

        if( SYSTEM.EB.PHM == ENABLE ){

        	SYSTEM.EB.PHP.STEP 		= disablePHM;
        	SYSTEM.EB.PHP.Counter 	= 0;
        	SYSTEM.EB.PHP.TryCounter = 0;

       		SYSTEM.POSITION.AVERAGE  = SYSTEM.EB.PHP.POSITION;
        	SYSTEM.POSITION.LASTHELD = SYSTEM.POSITION.AVERAGE;

			
        	CONFIG.POSITION	= SYSTEM.POSITION.LASTHELD;
//			CONFIG.PositionMode = POSITION_MODE_KNOWN;
        	SYSTEM.POSITION.PositionMode = POSITION_MODE_KNOWN;

        	CONFIG.WriteEvent = ON;
            return OK;

        } else  {
        	SetPHM(ENABLE);
        }
	}

    return FAIL;
}



char Setting_GMTOFFSET()
{
	int result;

    if( SYSTEM.EB.LOCALHOUR == 0 && SYSTEM.EB.LOCALMINUTE == 0 ){
        result = YES;
    }
    else {
    	SetGMTOFFSET(0,0);
        result = NO;
    }

    if(SYSTEM.IO.CTRL_PORT.MODE == UDEBUG){
        sprintf(MESG,"Local Hour:%d local Minute:%d\r\n",SYSTEM.EB.LOCALHOUR,SYSTEM.EB.LOCALMINUTE);
        TransmitMessage((BYTE*)MESG,DEBUG_PORT);
    }

    return result;

}


char Setting_ANTDLY()
{

    if(CONFIG.ANTDLY == SYSTEM.EB.ANTDLY){
        if(SYSTEM.IO.CTRL_PORT.MODE == UDEBUG){
            sprintf(MESG,"Antenna Delay :%ld\r\n",SYSTEM.EB.ANTDLY);
            TransmitMessage((BYTE*)MESG,DEBUG_PORT);
        }
        return YES;
    }
    else {
	     //sprintf((char*)MESG,"%ld : %ld \r\n",*antdly,SYSTEM.EB.ANTDLY);
	     //TransmitMessage(MESG,DEBUG_PORT);
         SetANTDLY(CONFIG.ANTDLY);
    }
    return NO;
}



char Setting_POSITION()
{
	
	SYSTEM.POSITION.PositionMode = CONFIG.PositionMode;
	
	// Position Hold Mode
	if( SYSTEM.POSITION.PositionMode == POSITION_MODE_KNOWN ){

        if( CONFIG.POSITION.LAT != 0 && CONFIG.POSITION.LON != 0 && CONFIG.POSITION.HEI != 0){
            SYSTEM.EB.PHP.POSITION = CONFIG.POSITION;
			SYSTEM.EB.PHP_Enable = ON;
	    }
        MessageOut("Known\r\n");

	}
	else {
		//Position Hold Mode Ǭ�
		SYSTEM.EB.PHM_Disable = ON;
		// Averaging mode ����ϰ�
        if( SYSTEM.POSITION.PositionMode == POSITION_MODE_DYNAMIC ){
        	SYSTEM.POSITION.Survey = SURVEY_OFF;
	        MessageOut("Dynamic\r\n");
        }
        else {
        	SYSTEM.POSITION.PositionMode = POSITION_MODE_AVERAGING;
        	//Start_Position_Survey(1);
        	Start_Position_Survey(0);
        	//SYSTEM.POSITION.Survey = SURVEY_ON;
	        MessageOut("Averaging\r\n");
        }
	}

    return OK;
}



char Setting_EBID()
{
	//SYSTEM.EB.ID = SYNC_15;
	//strcpy(Rcv_Version,"3.1");
	//return YES;
	
	if ( SYSTEM.EB.ID != UNDEFINED ) {

		Rcv_Version[0] = SYSTEM.EB.SWVER[0];
		Rcv_Version[1] = '.';
		Rcv_Version[2] = SYSTEM.EB.SWREV[0];
		Rcv_Version[3] = (char)0;
		return YES;
	}
	else {

		if(!(SYSTEM.EB.IntervalCounter%3)) {
			RequestEB(eRECEIVERID);
		}
		if(SYSTEM.EB.IntervalCounter > 60){

			//SYSTEM.EB.ID = UT_PLUS_ONCORE;
			//strcpy(Rcv_Version,"3.1");
			SYSTEM.EB.ID = SYNC_15;
			strcpy(Rcv_Version,"0.0");
		}
		return NO;
	}
}


char Setting_TIMEMODE()
{

    if(SYSTEM.EB.TIMEMODE == TIMEMODE_GPS ) {
        // MessageOut("Time Mode set to GPS\r\n");
    	return OK;
    } else {
        SetTIMEMODE(TIMEMODE_GPS);
    }
	return FAIL;
}


char SetEBToDefault()
{

    if (SYSTEM.EB.settodefault == OK){
    	// Position Mode  �8�Averaging Mode
    	Start_Position_Survey(0);

    	// restart
		EB_Task_start();
    	SYSTEM.EB.STATUS 		= EB_STATUS_ALMANAC;
   		SYSTEM.EB.almanac_step 	= EB_SET_PSDM;
        SYSTEM.EB.PSDM  		= UNDEFINED;
		SYSTEM.EB.UnlockedDelayCounter += 60;

        return YES;
    }
    else {
        RequestEB(eDEFAULT);
    }
    return NO;
}

void SetRcvDebug(unsigned char mode)
{
	if(mode == ENABLE){
    	EBTXParameter[0] = 0x01;
    }
    else if(mode == DISABLE){
    	EBTXParameter[0] = 0x00;
    }
    else{
    	EBTXParameter[0] = 0xFF;
    }
    
    RequestEB(eDEBUG_DISPLAY);    
}

void SetRcvThrDetect(unsigned char pit_1ms,unsigned char pit_4ms,unsigned char pit_20ms)
{
	EBTXParameter[0] = pit_1ms;
	EBTXParameter[1] = pit_4ms;
	EBTXParameter[2] = pit_20ms;
	
	RequestEB(eTHR_DETECT);
}

void SetRcvThrUnlock(unsigned char pit_1ms,unsigned char pit_4ms,unsigned char pit_20ms)
{
	EBTXParameter[0] = pit_1ms;
	EBTXParameter[1] = pit_4ms;
	EBTXParameter[2] = pit_20ms;
	
	RequestEB(eTHR_UNLOCK);
}


